#include "TestReporterStdout.hpp"
#include <cstdio>

#include "TestDetails.hpp"

namespace UnitTest {
    void TestReporterStdout::ReportFailure(TestDetails const& details, char const* failure)
    {
        using namespace std;
        char const* const errorFormat = "%s:%d:%d: error: Failure in %s: %s\n";
        fprintf(stderr, errorFormat, details.filename, details.lineNumber, 1, details.testName, failure);
    }

    void TestReporterStdout::ReportTestStart(TestDetails const& test)
    {
        printf("TestReporterStdout: Start Test [%s] =====\n", test.testName);
    }

    void TestReporterStdout::ReportTestFinish(TestDetails const& test, float)
    {
        printf("TestReporterStdout: Over Test [%s] ======\n", test.testName);
    }

    void TestReporterStdout::ReportSummary(int const totalTestCount, int const failedTestCount,
                                          int const failureCount, float const secondsElapsed)
    {
        using namespace std;
        if (failureCount > 0) {
            printf("FAILURE: %d out of %d tests failed (%d failures).\n", failedTestCount, totalTestCount, failureCount);
        } else {
            printf("Success: %d tests passed.\n", totalTestCount);
        }
        printf("Test time: %.2f seconds.\n", secondsElapsed);
    }
}
